﻿using System;
using System.Collections.Generic;
using System.Xml;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

namespace TaleWorlds.ObjectSystem
{
	// Token: 0x02000007 RID: 7
	public class MBObjectBase
	{
		// Token: 0x17000003 RID: 3
		// (get) Token: 0x06000017 RID: 23 RVA: 0x00002216 File Offset: 0x00000416
		// (set) Token: 0x06000018 RID: 24 RVA: 0x0000221E File Offset: 0x0000041E
		[SaveableProperty(1)]
		public string StringId { get; set; }

		// Token: 0x17000004 RID: 4
		// (get) Token: 0x06000019 RID: 25 RVA: 0x00002227 File Offset: 0x00000427
		// (set) Token: 0x0600001A RID: 26 RVA: 0x0000222F File Offset: 0x0000042F
		[SaveableProperty(2)]
		public MBGUID Id { get; set; }

		// Token: 0x17000005 RID: 5
		// (get) Token: 0x0600001B RID: 27 RVA: 0x00002238 File Offset: 0x00000438
		// (set) Token: 0x0600001C RID: 28 RVA: 0x00002240 File Offset: 0x00000440
		[CachedData]
		public bool IsInitialized { get; internal set; }

		// Token: 0x17000006 RID: 6
		// (get) Token: 0x0600001D RID: 29 RVA: 0x00002249 File Offset: 0x00000449
		// (set) Token: 0x0600001E RID: 30 RVA: 0x00002251 File Offset: 0x00000451
		[CachedData]
		public bool IsReady { get; set; }

		// Token: 0x17000007 RID: 7
		// (get) Token: 0x0600001F RID: 31 RVA: 0x0000225A File Offset: 0x0000045A
		// (set) Token: 0x06000020 RID: 32 RVA: 0x00002262 File Offset: 0x00000462
		[CachedData]
		[SaveableProperty(3)]
		internal bool IsRegistered { get; private set; }

		// Token: 0x06000021 RID: 33 RVA: 0x0000226B File Offset: 0x0000046B
		public MBObjectBase()
		{
		}

		// Token: 0x06000022 RID: 34 RVA: 0x00002273 File Offset: 0x00000473
		public MBObjectBase(MBObjectBase other)
		{
			this.StringId = other.StringId;
		}

		// Token: 0x06000023 RID: 35 RVA: 0x00002287 File Offset: 0x00000487
		public MBObjectBase(string stringId)
		{
			this.StringId = stringId;
		}

		// Token: 0x06000024 RID: 36 RVA: 0x00002296 File Offset: 0x00000496
		public void AfterInitialized()
		{
			if (this.IsRegistered)
			{
				this.IsReady = true;
			}
		}

		// Token: 0x06000025 RID: 37 RVA: 0x000022A7 File Offset: 0x000004A7
		public virtual void AfterRegister()
		{
		}

		// Token: 0x06000026 RID: 38 RVA: 0x000022A9 File Offset: 0x000004A9
		public virtual void Initialize()
		{
			this.IsInitialized = true;
		}

		// Token: 0x06000027 RID: 39 RVA: 0x000022B2 File Offset: 0x000004B2
		public virtual void Deserialize(MBObjectManager objectManager, XmlNode node)
		{
			this.Initialize();
			this.StringId = node.Attributes["id"].Value;
		}

		// Token: 0x06000028 RID: 40 RVA: 0x000022D5 File Offset: 0x000004D5
		[LoadInitializationCallback]
		private void BeforeLoad()
		{
			this.OnBeforeLoad();
		}

		// Token: 0x06000029 RID: 41 RVA: 0x000022DD File Offset: 0x000004DD
		protected virtual void OnBeforeLoad()
		{
			if (this.IsRegistered)
			{
				MBObjectManager.Instance.TryRegisterObjectWithoutInitialization(this);
				this.IsInitialized = true;
			}
		}

		// Token: 0x0600002A RID: 42 RVA: 0x000022FC File Offset: 0x000004FC
		public override int GetHashCode()
		{
			return this.Id.GetHashCode();
		}

		// Token: 0x0600002B RID: 43 RVA: 0x0000231D File Offset: 0x0000051D
		public virtual TextObject GetName()
		{
			return new TextObject(this.StringId, null);
		}

		// Token: 0x0600002C RID: 44 RVA: 0x0000232B File Offset: 0x0000052B
		protected virtual void PreAfterLoad()
		{
		}

		// Token: 0x0600002D RID: 45 RVA: 0x0000232D File Offset: 0x0000052D
		public void PreAfterLoadInternal()
		{
			this.PreAfterLoad();
		}

		// Token: 0x0600002E RID: 46 RVA: 0x00002335 File Offset: 0x00000535
		protected virtual void AfterLoad()
		{
		}

		// Token: 0x0600002F RID: 47 RVA: 0x00002337 File Offset: 0x00000537
		public void AfterLoadInternal()
		{
			this.AfterLoad();
		}

		// Token: 0x06000030 RID: 48 RVA: 0x0000233F File Offset: 0x0000053F
		public void OnRegistered()
		{
			this.IsRegistered = true;
			this.AfterRegister();
		}

		// Token: 0x06000031 RID: 49 RVA: 0x0000234E File Offset: 0x0000054E
		public void OnUnregistered()
		{
			this.IsRegistered = false;
		}

		// Token: 0x06000032 RID: 50 RVA: 0x00002357 File Offset: 0x00000557
		internal static void AutoGeneratedStaticCollectObjectsMBObjectBase(object o, List<object> collectedObjects)
		{
			((MBObjectBase)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
		}

		// Token: 0x06000033 RID: 51 RVA: 0x00002365 File Offset: 0x00000565
		protected virtual void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
		{
		}

		// Token: 0x06000034 RID: 52 RVA: 0x00002367 File Offset: 0x00000567
		internal static object AutoGeneratedGetMemberValueStringId(object o)
		{
			return ((MBObjectBase)o).StringId;
		}

		// Token: 0x06000035 RID: 53 RVA: 0x00002374 File Offset: 0x00000574
		internal static object AutoGeneratedGetMemberValueId(object o)
		{
			return ((MBObjectBase)o).Id;
		}

		// Token: 0x06000036 RID: 54 RVA: 0x00002386 File Offset: 0x00000586
		internal static object AutoGeneratedGetMemberValueIsRegistered(object o)
		{
			return ((MBObjectBase)o).IsRegistered;
		}
	}
}
